home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectSound / StreamData / readme.txt < prev    next >
Encoding:
Text File  |  2001-10-10  |  4.2 KB  |  90 lines

  1. //-----------------------------------------------------------------------------
  2. // 
  3. // Sample Name: StreamData Sample
  4. // 
  5. // Copyright (c) 1999-2001 Microsoft Corporation. All rights reserved.
  6. // 
  7. //-----------------------------------------------------------------------------
  8.  
  9.  
  10. Description
  11. ===========
  12.   The StreamData sample shows how to stream a wave file through a DirectSound 
  13.   secondary buffer. It is similar to the PlaySound sample, but adds support 
  14.   for streaming.
  15.  
  16. Path
  17. ====
  18.   Source: DXSDK\Samples\Multimedia\DSound\StreamData
  19.  
  20.   Executable: DXSDK\Samples\Multimedia\DSound\Bin
  21.  
  22. User's Guide
  23. ============
  24.   Load a wave file by clicking Sound File. Select Loop Sound if you want it 
  25.   to play repeatedly. Click Play.
  26.  
  27. Programming Notes
  28. =================
  29.   For details on how to setup a non-streaming DirectSound buffer, see the 
  30.   PlaySound sample. 
  31.  
  32.   The basic tasks to stream data from a wav file to a DirectSound buffer are
  33.   as follows:
  34.   
  35.   * Set up DirectSound: 
  36.      1. Call DirectSoundCreate to create a IDirectSound object
  37.      2. Call IDirectSound::SetCooperativeLevel to set the cooperative level.
  38.      3. Set the primary buffer format.  This sample calls 
  39.         DSUtil_SetPrimaryBufferFormat() to do just this. 
  40.        
  41.   * Create a DirectSound buffer and set up the notifications:
  42.      1. Read the wav file to get the wav file size, and the wav format 
  43.         in the format a WAVEFORMATEX structure.
  44.      2. Choose a DirectSound buffer size.  This is the amount of data that 
  45.         DirectSound stores at once.  You re-fill this buffer as sound plays 
  46.         from this buffer.  This is best for large sounds files that are not 
  47.         possible to load all at once.  For this sample, the buffer size is 
  48.         ~3 seconds of data.
  49.      3. Create a DirectSound buffer using the buffer size, and the wav file's 
  50.         format.  Also pass in DSBCAPS_CTRLPOSITIONNOTIFY flag.  This allows the 
  51.         buffer to send notification events to tell us whenever sound has finished 
  52.         playing.  However, using this flags limits the buffer to software only,
  53.         since hardware can not signal position notifications. 
  54.      4. Set up the notifications on the buffer by calling 
  55.         IDirectSoundBuffer::SetNotificationPositions.  See InitDSoundNotification() 
  56.         for an example of how this is done.  When DirectSound plays past a 
  57.         notification position it signals an Win32 event.  When this event is signaled,
  58.         it is safe to fill that segment of data in the buffer with a new piece of 
  59.         sound.
  60.         
  61.   * Play the DirectSound buffer:
  62.      1. Call IDirectSoundBuffer::Restore on the buffer if the buffer was lost.
  63.      2. Next, fill the DirectSound buffer will the maximum amount of sound data.  
  64.         Since all the sound can not fit into this buffer will be filled with new 
  65.         sound data as this sound plays.  
  66.      3. Call IDirectSoundBuffer::Play with the DSBPLAY_LOOPING flag set to 
  67.         start the buffer playing.  The looping flag needs to be set since the 
  68.         buffer will need to continue playing after the end of the buffer is 
  69.         reached since typically more sound needs to be played.  
  70.      
  71.   * Check to see if a notification is signaled:
  72.       1. Typically in the message pump check to see if the event was signaled.  
  73.          The event tells us that a segment of data has been played so this 
  74.          piece need to be filled. MsgWaitForMultipleObjects() works well as 
  75.          the message pump for this purpose.  
  76.       2. If the event has been signaled, then lock the section of the buffer 
  77.          than has just been played and fill it with the next segment of wav 
  78.          data.  See HandleNotification() for how this works.  
  79.                 
  80.   * When the entire sound has played:      
  81.      When handling the event notification, keep track of how much data has 
  82.      been put in the buffer.  When the entire wav file has been put into the 
  83.      buffer, and after DirectSound has played it all it is necessary to manually
  84.      stop the buffer since the buffer will continuously loop otherwise.  
  85.          
  86.   * Free DirectSound:
  87.      Simply call Release() on all the DirectSound objects that were created.
  88.   
  89.  
  90.